package com.SDU.policedispatch.service.impl.department;

import com.SDU.policedispatch.entity.*;
import com.SDU.policedispatch.mapper.DepartmentMapper;
import com.SDU.policedispatch.mapper.PersonnelInfoMapper;
import com.SDU.policedispatch.mapper.ScheduleMapper;
import com.SDU.policedispatch.service.department.DepartmentListService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
*
*  已弃用
*
* */

@Service
public class DepartmentListServiceImpl implements DepartmentListService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Autowired
    private ScheduleMapper scheduleMapper;

    @Autowired
    private PersonnelInfoMapper personnelInfoMapper;

    @Override
    public Map<java.lang.String, Object> GetDepartmentDutyList(String departmentName) {
        Map<java.lang.String, Object> map = new HashMap<>();
        map.put("部门名称", departmentName);
        QueryWrapper<Department> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dept_name", departmentName);
        Department department = departmentMapper.selectOne(queryWrapper);
        // 值班人员
        List<Schedules> main = scheduleMapper.SelectPerson("主班", departmentName);
        List<java.lang.String> res = new ArrayList<>();
        // 值班领导(目前是空)
        map.put("值班领导", res.toString());
        for(Schedules ele: main) {
            Person per = new Person(ele.getId(), ele.getName());
            res.add(JSON.toJSONString(per));
        }
        map.put("值班人员", res.toString());
        // 副班人员
        List<Schedules> list2 = scheduleMapper.SelectPerson("副班", departmentName);
        res.clear();
        for(Schedules ele: list2) {
            Person per = new Person(ele.getId(), ele.getName());
            res.add(JSON.toJSONString(per));
        }
        map.put("副班", res.toString());
        return map;
    }

    @Override
    public Map<java.lang.String, Object> GetCommandCenterDutyList() {
        Map<String, Object> map = new HashMap<>();
        List<Schedules> 总指挥长 = scheduleMapper.SelectByLeader("总指挥长");
        List<String> 总指挥长Person = new ArrayList<>();
        for(Schedules s: 总指挥长) {
            Person per = new Person(s.getId(), s.getName());
            总指挥长Person.add(JSON.toJSONString(per));
        }
        map.put("总指挥长", 总指挥长Person);
        List<Schedules> 专职指挥长 = scheduleMapper.SelectByLeader("专职指挥长");
        List<String> 专职指挥长Person = new ArrayList<>();
        for(Schedules s: 专职指挥长) {
            Person per = new Person(s.getId(), s.getName());
            专职指挥长Person.add(JSON.toJSONString(per));
        }
        map.put("专职指挥长", 专职指挥长Person);
        List<Schedules> 接警班组 = scheduleMapper.SelectByLeader("接警班组");
        List<String> 接警班组Person = new ArrayList<>();
        for(Schedules s: 接警班组) {
            Person per = new Person(s.getId(), s.getName());
            接警班组Person.add(JSON.toJSONString(per));
        }
        map.put("接警班组", 接警班组Person);
        return map;
    }

    @Override
    public Map<java.lang.String, Object> GetCenterDutyList() {
        Map<String, Object> map = new HashMap<>();
        List<Schedules> 值班领导 = scheduleMapper.SelectByLeader("值班领导");
        List<String> 值班领导Person = new ArrayList<>();
        for(Schedules s: 值班领导) {
            Person per = new Person(s.getId(), s.getName());
            值班领导Person.add(JSON.toJSONString(per));
        }
        map.put("接警班组", 值班领导Person);
        List<Schedules> 调度会参与领导 = scheduleMapper.SelectByLeader("调度会参与领导");
        List<String> 调度会参与领导Person = new ArrayList<>();
        for(Schedules s: 调度会参与领导) {
            Person per = new Person(s.getId(), s.getName());
            调度会参与领导Person.add(JSON.toJSONString(per));
        }
        map.put("调度会参与领导", 调度会参与领导Person);
        List<Schedules> 指挥中心值班 = scheduleMapper.SelectByLeader("指挥中心值班");
        List<String> 指挥中心值班Person = new ArrayList<>();
        for(Schedules s: 指挥中心值班) {
            Person per = new Person(s.getId(), s.getName());
            指挥中心值班Person.add(JSON.toJSONString(per));
        }
        map.put("指挥中心值班", 指挥中心值班Person);
        map.put("情指中心", GetCommandCenterDutyList());
        return map;
    }

    @Override
    public Map<java.lang.String, Object> GetDutyList() {
        Map<String, Object> map = new HashMap<>();
        List<Department> list = departmentMapper.selectList(null);
        List<Map<String, Object>> DepartmentDutyList = new ArrayList<>();
        for(Department d: list) {
            //DepartmentDutyList.add(GetDepartmentDutyList(d.getDeptName())); // Stupid
        }
        map.put("各部门", DepartmentDutyList);
        map.put("相应等级", "无");
        map.put("中心", GetCenterDutyList());
        return map;
    }

    @Override
    public List<Person> GetMembers(String dept) {
        QueryWrapper<PersonnelInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dept_name", dept);
        List<PersonnelInfo> list = personnelInfoMapper.selectList(queryWrapper);
        List<Person> resp = new ArrayList<>();
        for(PersonnelInfo p: list) {
            Person person = new Person(p.getId(), p.getName());
            resp.add(person);
        }
        return resp;
    }
}
